package com.boot.security.server.controller.mffl.MfflRefund;

import com.boot.security.server.dao.mffl.MfflRefundDao;
import com.boot.security.server.model.mffl.MfflRefund;
import com.boot.security.server.model.mffl.Vo.MfflRefundVo;
import com.boot.security.server.page.table.PageTableHandler;
import com.boot.security.server.page.table.PageTableHandler.CountHandler;
import com.boot.security.server.page.table.PageTableHandler.ListHandler;
import com.boot.security.server.page.table.PageTableRequest;
import com.boot.security.server.page.table.PageTableResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@ApiIgnore
@RestController
@RequestMapping("/client/mfflRefunds")
public class client_MfflRefundController {

    @Autowired
    private MfflRefundDao mfflRefundDao;

    @PostMapping
    @ApiOperation(value = "保存")
    public MfflRefund save(@RequestBody MfflRefund mfflRefund) {
        mfflRefundDao.save(mfflRefund);

        return mfflRefund;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    public MfflRefund get(@PathVariable Long id) {
        return mfflRefundDao.getById(id);
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public MfflRefund update(@RequestBody MfflRefund mfflRefund) {
        mfflRefundDao.update(mfflRefund);

        return mfflRefund;
    }

    @GetMapping
    @ApiOperation(value = "列表")
    public PageTableResponse list(PageTableRequest request) {
        return new PageTableHandler(new CountHandler() {

            @Override
            public int count(PageTableRequest request) {
                return mfflRefundDao.count(request.getParams());
            }
        }, new ListHandler() {

            @Override
            public List<MfflRefundVo> list(PageTableRequest request) {
                return mfflRefundDao.list(request.getParams(), request.getOffset(), request.getLimit());
            }
        }).handle(request);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public void delete(@PathVariable Long id) {
        mfflRefundDao.delete(id);
    }
}
